<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="public:meta" />
	<link href="../public/css/personal/common.css" rel="stylesheet" type="text/css" />
	<link href="../public/css/personal/personal_user.css" rel="stylesheet" type="text/css" />
	<link href="../public/css/personal/personal_ajax_dialog.css" rel="stylesheet" type="text/css" />
	<script src="../public/js/personal/jquery.common.js" type="text/javascript" language="javascript"></script>
</head>
<body>
<include file="public:header_other" />
<div class="us-top">
    <div class="us-main">
        <div class="us-top-box">
            <form id="ajax_search_location" action="{:U('ajaxCommon/ajax_search_location',array('type'=>'QS_jobslist'))}" method="get">
                <div class="input-box"><input type="text" name="key" data-original="请输入关键字" value="" placeholder="请输入关键字" autocomplete="off"></div>
                <div class="se-btn"><input type="submit" value="搜 索"></div>
                <div class="clear"></div>
            </form>
        </div>
    </div>
</div>
	<div class="user_main">
		<include file="Personal:index_left_nav" />
  	  <div class="mainbox">
			<!--切换卡 -->
			<div class="tab">
				<a class="li J_hoverbut" href="{:U('index')}">我的{:C('qscms_points_byname')}</a>
				<a class="li J_hoverbut " href="{:U('task')}" >我的任务</a>
				<a class="li select " href="{:U('increment')}">增值服务</a>
				<a class="li J_hoverbut " href="{:U('order_list')}">服务订单</a>
				<notempty name="apply['Mall']">
					<a class="li J_hoverbut " href="{:U('order_list_goods')}">商城订单</a>
				</notempty>
			  	<div class="clear"></div>
			</div>

			<!--切换卡结束 -->
			<div class="order_add">
		    <form target="_blank" id="cash_pay_form" method="post" action="{:U('increment_add_save')}">
			  <div class="lefttit">服务名称：</div>
			  <div class="rights">
			    <div class="sname font_blue">简历模板</div>
			  </div>
			  	<div class="lefttit">选择模板：</div>			  
			  <div class="rights">
			  		<volist name="choose_arr" id="vo">
			  			<div class="tpl J_hoverbut <if condition="$key eq 0">select</if> tpl_tab" tplid="{$vo['tpl_id']}" points="{$vo['tpl_val']}">
						  	<div class="hook"></div>
					  	  	<div class="name">{$vo['tpl_name']}</div>
							<div class="thumbnail"><img src="{$vo['thumb_dir']}/thumbnail.jpg" /></div>
							<div class="preview">
							  	<div class="lp link_blue"><a target="_blank" href="{:url_rewrite('QS_resumeshow',array('id'=>$def_resume['id'],'style'=>$vo['tpl_dir']))}">预览模板</a></div>
							  	<div class="rp">{$vo['tpl_val']} {:C("qscms_points_byname")}</div>
							  	<div class="clear"></div>
						  	</div>
						</div>
					</volist>	
					<div class="clear"></div>
			  	</div>
				<input type="hidden" id="tplid" name="tplid" value="{$choose_arr[0]['tpl_id']}">
				<input type="hidden" id="points" name="points" value="{$choose_arr[0]['tpl_val']}">
				<input type="hidden" id="mypoints" value="{$mypoints}">
			   <div class="lefttit">支付方式：</div>
			  <div class="rights">
				   <div class="pay_select">
						 <!--小标题切换卡 -->
						<div class="thtab">
							<div class="li J_hoverbut select points_tab" >{:C('qscms_points_byname')}兑换</div>
							<div class="li J_hoverbut cash_tab"  >现金支付</div>
							<div class="clear"></div>
						</div>
				   </div>
			  </div>
			  <div class="clear"></div>
			  
			<!--积分支付 -->
			<div class="tabshow" id="points_wrap" style="display:block">
				<div class="enough">
					<div class="lefttit">所需{:C('qscms_points_byname')}：</div>
				  	<div class="rights">
				    	<div class="count link_blue"> 
					  		<strong class="need_points"></strong>{:C('qscms_points_byname')}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前拥有 <span>{$mypoints}</span> {:C('qscms_points_byname')}，<a href="{:U('task')}">做任务</a> 还可以获得更多{:C('qscms_points_byname')}哦！
					  	</div>
			 	  	</div>
				  	<div class="clear"></div>
				  	<div class="lefttit">&nbsp;</div>
				  	<div class="rights">
				     	<input name="" type="button" id="points_pay_submit" class="btn_yellow J_hoverbut btn_100_38" value="立即兑换" />
				  	</div>
				</div>
			  	<div class="notenough" style="display:none">
			  		<div class="lefttit">所需{:C('qscms_points_byname')}：</div>
				  	<div class="rights">
				    	<div class="count link_blue"> 
							<strong class="need_points"></strong>{:C('qscms_points_byname')}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前拥有 <span>{$mypoints}</span> {:C('qscms_points_byname')}，不足以兑换次服务，建议您 <a href="{:U('task')}">做任务</a> 获得更多{:C('qscms_points_byname')}！
						</div>
		 	  		</div>
				  	<div class="clear"></div>
				  	<div class="lefttit">&nbsp;</div>
				  	<div class="rights">
				    	<input name="" type="button" class="btn_yellow J_hoverbut btn_100_38 btn_disabled" value="立即兑换" />
				 	</div>
			  	</div>
			  	<div class="clear"></div>
			</div>
			  
		    <div class="tabshow" id="cash_wrap">
				<div class="lefttit">&nbsp;</div>
			  	<div class="rights">
					<!--默认是不做任何选择 没有select -->
					<volist name="payment" id="vo">
					<div typename="{$vo['typename']}" class="pays J_hoverbut"><img src="../public/images/pay_{$vo['typename']}.png"   border="0"/>
						<div class="hook"></div>
					</div>
					</volist>
					<!-- <div class="pays J_hoverbut">
						<img src="../public/images/pay_weixn.png" border="0"/>
						<div class="hook"></div>
					</div> -->
					<div class="clear"></div>	
			  	</div>
				<div class="lefttit">订单价格：</div>
				<div class="rights">
				    <div class="price"><strong id="need_cash"></strong>元</div>
				</div>
				<input type="hidden" id="amount" name="amount" value="">
				<input type="hidden" name="payment_name" id="payment_name" value="">
				<input type="hidden" name="pay_type" value="cash">
				<input type="hidden" name="type" value="tpl">
				<input type="hidden" name="is_deductible" id="is_deductible" value="1"><!-- 是否选中使用积分抵现 -->
				<input type="hidden" name="deductible" id="deductible" value=""><!-- 抵现积分 -->
				<div class="lefttit">&nbsp;</div>
				<div class="rights">
					<input name="" type="button" id="cash_pay_submit" class="btn_yellow J_hoverbut btn_100_38" value="立即支付" />
				</div>
		    </div>
		</div>
		</form>
		</div>
				<div class="clear"></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
	<include file="Personal:index_footer" />
	<script type="text/javascript">
		$(document).ready(function(){
			$(".tpl_tab").click(function(){
				$(this).siblings().removeClass('select');
				$(this).addClass('select');
				$("#tplid").val($(this).attr("tplid"));
				$("#points").val($(this).attr("points"));
				select_pay_type(1);
			});
			function select_pay_type(no_change_tab){
				var mypoints = parseInt($("#mypoints").val());
				var current_points = parseInt($("#points").val());
				if(mypoints<current_points){
					if(no_change_tab==0){
						$(".pay_select .li").removeClass('select');
						$(".cash_tab").addClass('select');
						$("#points_wrap").hide();
						$("#cash_wrap").show();
					}
					$('#J_integralforcash_input').val(mypoints);
					$('#deductible').val(mypoints);
					$(".enough").hide();
					$(".notenough").show();
				}else{
					if(no_change_tab==0){
						$(".pay_select .li").removeClass('select');
						$(".points_tab").addClass('select');
						$("#cash_wrap").hide();
						$("#points_wrap").show();
					}
					$('#J_integralforcash_input').val(current_points);
					$('#deductible').val(current_points);
					$(".enough").show();
					$(".notenough").hide();
				}
				$(".need_points").html(current_points);
				var need_cash = current_points/parseInt("{$payment_rate}");
				$("#need_cash").html(need_cash.toFixed(2));
				$("#amount").val(need_cash.toFixed(2));
				$('#J_integralforcashvalue').text(($('#J_integralforcash_input').val()/parseInt("{$payment_rate}")).toFixed(2));
				if ($('#J_integralforcash').is(':checked')) {
					$("#pay_cash").text((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#amount').val((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
				} else {
					$("#pay_cash").html(need_cash.toFixed(2));
					$('#amount').val(need_cash.toFixed(2));
				}
			}
			select_pay_type(0);
			$(".duration").click(function(){
				$(this).siblings().removeClass('select');
				$(this).addClass('select');
				$("#days").val($(this).attr('days'));
				$("#points").val($(this).attr('points'));
				select_pay_type(1);
			});
			$('#J_integralforcash_input').keyup(function() {
				var mypoints = parseInt($("#mypoints").val());
				var current_points = parseInt($("#points").val());
				var minpointsValue = mypoints >= current_points ? current_points : mypoints;
				var thisvalue = $(this).val();
				if (thisvalue > minpointsValue) {
					$('#J_integralforcash_input').val(minpointsValue);
				};
				$('#J_integralforcashvalue').text(($('#J_integralforcash_input').val()/parseInt("{$payment_rate}")).toFixed(2));
				$('#deductible').val($('#J_integralforcash_input').val());
				if($('#J_integralforcash').is(':checked')){
					$("#pay_cash").text((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#amount').val((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
				}
			});
			$('#J_integralforcash').click(function() {
				if ($('#J_integralforcash').is(':checked')) {
					$("#pay_cash").text((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#amount').val((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#is_deductible').val('1');
				} else {
					$("#pay_cash").html(parseFloat($('#need_cash').text()).toFixed(2));
					$('#amount').val(parseFloat($('#need_cash').text()).toFixed(2));
					$('#is_deductible').val('0');
				}
			});
			
			$("#points_pay_submit").click(function(){
				ajax_pay('tpl','points');
			});
			$(".pays").click(function(){
				$(this).siblings().removeClass('select');
				$(this).addClass('select');
				$("#payment_name").val($(this).attr("typename"));
			});
			$("#cash_pay_submit").click(function(){

				if(!$("#payment_name").val()){
					disapperTooltip("remind","请选择支付方式！");
					return false;
				}
				if(parseFloat($("#amount").val())==0.00){
					ajax_pay('tpl','points');
				}else{
					if($("#payment_name").val()=='wxpay'){
						var qsDialog = $(this).dialog({
			        		title: '微信支付',
							loading: true,
							showFooter: false
						});
						$.ajax({
			                cache: true,
			                type: "POST",
			                url:"{:U('increment_add_save')}",
			                data:$('#cash_pay_form').serialize(),
			                dataType:"json",
			                success: function(result) {
			                    if(result.status==1){
			                    	qsDialog.setContent("<div style='width:250px;'><img src='"+result.data+"' alt='扫描二维码' width='250' height='250' /></div>");
									window.setInterval(run, 5000);
			                    }else{
			                    	qsDialog.setContent('<div class="confirm">' + result.msg + '</div>');
									return false;
			                    }
			                }
			            });
					}else{
						var url = "{:U('PersonalService/confirm_pay_status')}";
						var qsDialog=$(this).dialog({
							title: '确认支付',
							loading: true,
							border: false,
							yes: function() {
								window.location.href="{:U('Personal/index')}";
							},
							cancel:function(){
								window.location.href="{:U('PersonalService/order_list')}";
							}
						});
						$.getJSON(url,function(result){
			        		if(result.status == 1){
			        			qsDialog.setContent(result.data.html);
			        			qsDialog.setBtns(['支付完成', '遇到问题']);
			        		}else{
			        			disapperTooltip('remind',result.msg);
			        		}
			        	});
						$("#cash_pay_form").submit();
					}
				}
			});

		});
		
        function run(){
            $.getJSON("{:U('check_weixinpay_notify')}",function(result){
                if(result.status==1){
                   location.href=result.data;
                }
            });
        }
        function ajax_pay(type,pay_type){
			var tplid = $("#tplid").val();
			var payment_name = "points";
			$.post("{:U('increment_add_save')}",{pay_type:pay_type,type:type,payment_name:payment_name,tplid:tplid},function(result){
				if(result.status==1){
					disapperTooltip("success", "兑换成功！");
					setTimeout(function () {
                        location.href='{:U("Personal/index")}';
                    }, 2000);
				}else{
					disapperTooltip("remind", result.msg);
					return false;
				}
			},'json');
        }
	</script>
</body>
</html>